/**
 * 
 */
package com.leyu.mall.site.search.controller;

import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

/**
 * @author change
 * 
 */
public class CategoryView implements Cloneable {
	final Set<IdText> areas = new LinkedHashSet<IdText>();
	final Set<IdText> brands = new LinkedHashSet<IdText>();
	final Set<IdText> priceRanges = new LinkedHashSet<IdText>();
	final Set<IdText> systems = new LinkedHashSet<IdText>();
	final Set<IdText> screens = new LinkedHashSet<IdText>();
	final Set<IdText> specials = new LinkedHashSet<IdText>();
	final Set<IdText> sorts = new LinkedHashSet<IdText>();
	Object[] cateArrays = { areas, brands, priceRanges, systems, screens,
			specials};
	String [] pnames ={"area","brand","price","os","screen","sp"};

	final Set<IdText> selecteds=new LinkedHashSet<IdText>();
	public CategoryView() {
		for (Object item : cateArrays) {
			Set<IdText> idTextSet = (Set<IdText>) item;
			IdText idText = new IdText();
			idText.id = 0L;
			idText.text = "不限";
			idTextSet.add(idText);
		}

	}

	public IdText selected(String pname,String value){
		if(StringUtils.isBlank(value)||!StringUtils.isNumeric(value)){
			return null;
		}
		IdText result=null;
		for(int i=0;i<pnames.length;i++){
			String item=pnames[i];
			if(item.equals(pname)){
				Set<IdText> idTextSet=(Set<IdText>) cateArrays[i];
				for(IdText idText:idTextSet){
					if(!idText.id.toString().equals("0")&&idText.id.toString().equals(value)){
						result=idText; 
						break;
					}
				}
				break;
			}
		}
		if(result!=null){
			return result.clone();
		}
		return result;
	}
	public Set<IdText> getAreas() {
		return areas;
	}

	public Set<IdText> getBrands() {
		return brands;
	}

	public Set<IdText> getPriceRanges() {
		return priceRanges;
	}

	public Set<IdText> getSystems() {
		return systems;
	}

	public Set<IdText> getScreens() {
		return screens;
	}

	public Set<IdText> getSpecials() {
		return specials;
	}

	public Set<IdText> getSorts() {
		return sorts;
	}

	public Set<IdText> getSelecteds() {
		return selecteds;
	}

	@Override
	public CategoryView clone() { 
		CategoryView view = new CategoryView();
		for (int i=0;i<cateArrays.length;i++) {
			Set<IdText> idSet = (Set<IdText>) cateArrays[i];
			Set<IdText> idSet2= (Set<IdText>) view.cateArrays[i];
			for(IdText item:idSet){ 
				idSet2.add(item.clone());
			}
		}
		for(IdText item:sorts){ 
			view.sorts.add(item.clone());
		}
		return view;
	}

}
